package com.net.shop.car.manager.ui.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.shop.car.manager.Constant;
import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.CardItem;
import com.net.shop.car.manager.ui.personalcenter.oil.OildCardDialog;

public class OildQuiryAdapter extends BaseAdapter {
	Context context;
	ArrayList<CardItem> list;
	OildCardDialog dialog;
	int current_pos;	//当前选定的position
	View current_view;
	boolean IsClick=true;
	int i;
	public OildQuiryAdapter(Context context, ArrayList<CardItem> list,
			OildCardDialog dialog,int i) {
		this.context = context;
		this.list = list;
		this.dialog = dialog;
		this.i=i;
		current_pos = -1;
		current_view = null;
	}

	@Override
	public int getCount() {
		return list.size();
	}
	

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		Button btn;
		ImageView img;
		
		if(null == convertView)
			convertView = View.inflate(context,R.layout.oild_quiry, null);
		img=(ImageView)	convertView.findViewById(R.id.oild_selected);
		
		
		if(current_pos == position)
			img.setBackgroundResource(R.drawable.selected);
		else
			img.setBackgroundResource(R.drawable.notselected);
		
		
		img.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(null != current_view)
					current_view.setBackgroundResource(R.drawable.notselected);
				v.setBackgroundResource(R.drawable.selected);
				current_view = v;
				current_pos = position;
			}
		});
		
		
		
//		
//		switch (i) {
//		case 1:
//			 btn = (Button) convertView.findViewById(R.id.oild_charge_btn);
//			 img=(ImageView)convertView.findViewById(R.id.oild_selected);
//			 
//			 img.setVisibility(View.GONE);
//			 btn.setOnClickListener(new OnClickListener() {
//			 @Override
//			 public void onClick(View v) {
//				 Intent intent = new Intent();  //Itent就是我们要发送的内容
//				 intent.putExtra("number",list
//							.get(position).getId());
//				 intent.putExtra("name",list
//							.get(position).getName());
//		            intent.setAction("data");   //设置你这个广播的action，只有和这个action一样的接受者才能接受者才能接收广播
//		            context.sendBroadcast(intent);   //发送广播
//			 }
//			 });
//			((TextView) convertView.findViewById(R.id.oild_number)).setText(list
//					.get(position).getId() + "");
//			((TextView) convertView.findViewById(R.id.oild_name)).setText(list
//					.get(position).getName() + "");
//			
//
//			break;
//		case 2:
//			btn = (Button) convertView.findViewById(R.id.oild_charge_btn);
//			img=(ImageView)convertView.findViewById(R.id.oild_selected);
//			img.setVisibility(View.VISIBLE);
//			btn.setVisibility(View.GONE);
//			
//			((TextView) convertView.findViewById(R.id.oild_number)).setText(list
//					.get(position).getId() + "");
//			((TextView) convertView.findViewById(R.id.oild_name)).setText(list
//					.get(position).getName() + "");
//			
//			break;
//
//		}
		
		return convertView;
	}

}
